{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "# 假设你的数据是一个CSV文件，可以通过read_csv加载\n",
    "# 如果数据不是CSV格式，可以根据实际情况使用其他read_函数\n",
    "data = pd.read_csv('../alpha=0.1.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>p</th>\n",
       "      <th>r</th>\n",
       "      <th>f1</th>\n",
       "      <th>time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.1</td>\n",
       "      <td>50</td>\n",
       "      <td>0.77</td>\n",
       "      <td>1.47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.1</td>\n",
       "      <td>45</td>\n",
       "      <td>0.74</td>\n",
       "      <td>1.45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.1</td>\n",
       "      <td>35</td>\n",
       "      <td>0.70</td>\n",
       "      <td>1.43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.1</td>\n",
       "      <td>30</td>\n",
       "      <td>0.68</td>\n",
       "      <td>1.40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.1</td>\n",
       "      <td>25</td>\n",
       "      <td>0.63</td>\n",
       "      <td>1.39</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     p   r    f1  time\n",
       "0  0.1  50  0.77  1.47\n",
       "1  0.1  45  0.74  1.45\n",
       "2  0.1  35  0.70  1.43\n",
       "3  0.1  30  0.68  1.40\n",
       "4  0.1  25  0.63  1.39"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "特征 X:\n",
      "      p   r\n",
      "0  0.1  50\n",
      "1  0.1  45\n",
      "2  0.1  35\n",
      "3  0.1  30\n",
      "4  0.1  25\n",
      "目标 y:\n",
      " 0    0.77\n",
      "1    0.74\n",
      "2    0.70\n",
      "3    0.68\n",
      "4    0.63\n",
      "Name: f1, dtype: float64\n"
     ]
    }
   ],
   "source": [
    "X = data.iloc[:, :-2]  # 选择除最后一列之外的所有列作为特征\n",
    "f1 = data.iloc[:, -2]   # 选择最后一列作为目标变量\n",
    "time = data.iloc[:,-1]\n",
    "# 打印 X 和 y，确保提取正确\n",
    "print(\"特征 X:\\n\", X.head())\n",
    "print(\"目标 y:\\n\", f1.head())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "回归系数： [-0.92813953  0.00513953]\n",
      "截距： 0.6066511627906976\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "from sklearn.linear_model import LinearRegression\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# 生成一些示例数据\n",
    "# np.random.seed(0)\n",
    "# X = 2 * np.random.rand(100, 2)  # 有两个特征\n",
    "# y = 4 + 3 * X[:, 0] + 2 * X[:, 1] + np.random.randn(100)\n",
    "\n",
    "# 创建线性回归模型\n",
    "model = LinearRegression()\n",
    "\n",
    "# 将数据拟合到模型中\n",
    "model.fit(X, f1)\n",
    "\n",
    "# 打印回归系数和截距\n",
    "print(\"回归系数：\", model.coef_)\n",
    "print(\"截距：\", model.intercept_)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "回归系数： [-0.53418605  0.00318605]\n",
      "截距： 1.36353488372093\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "from sklearn.linear_model import LinearRegression\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# 生成一些示例数据\n",
    "# np.random.seed(0)\n",
    "# X = 2 * np.random.rand(100, 2)  # 有两个特征\n",
    "# y = 4 + 3 * X[:, 0] + 2 * X[:, 1] + np.random.randn(100)\n",
    "\n",
    "# 创建线性回归模型\n",
    "model = LinearRegression()\n",
    "\n",
    "# 将数据拟合到模型中\n",
    "model.fit(X, time)\n",
    "\n",
    "# 打印回归系数和截距\n",
    "print(\"回归系数：\", model.coef_)\n",
    "print(\"截距：\", model.intercept_)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "diffusionA",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
